<template>
	<el-dialog :title="!dataForm.id ? '新建' :  isDetail ? '详情':'编辑'" :close-on-click-modal="false" :visible.sync="visible" class="JNPF-dialog JNPF-dialog_center" lock-scroll width="600px">
		<el-row :gutter="15" class="" >
			<el-form ref="elForm" :model="dataForm" size="medium" label-width="100px" label-position="right" :disabled="!!isDetail" :rules="rules">
				

        <el-col :span="24">
					<el-form-item label="最小推广人数" prop="minNumber" required >
						<el-input-number v-model="dataForm.minNumber" placeholder="数字文本" :step="1" controls-position="" >
						</el-input-number>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="最大推广人数" prop="maxNumber" required >
						<el-input-number v-model="dataForm.maxNumber" placeholder="数字文本" :step="1" controls-position="" >
						</el-input-number>
					</el-form-item>
				</el-col>
        
        
        <el-col :span="24">
					<el-form-item label="最小月份" prop="min" required >
						<el-input-number v-model="dataForm.min" placeholder="数字文本" :step="1" controls-position="" >
						</el-input-number>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="最大月份" prop="max" required >
						<el-input-number v-model="dataForm.max" placeholder="数字文本" :step="1" controls-position="" >
						</el-input-number>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="提成比例" prop="commission" required >
						<el-input-number v-model="dataForm.commission" placeholder="数字文本" :step="1" controls-position="" >
						</el-input-number>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="描述" prop="description" >
						<el-input v-model="dataForm.description" placeholder="请输入" show-word-limit :style='{"width":"100%"}' type="textarea" :autosize='{"minRows":4,"maxRows":4}' >
						</el-input>
					</el-form-item>
				</el-col>
			</el-form>
		</el-row>
		<span slot="footer" class="dialog-footer">
			<el-button @click="visible = false">取 消</el-button> 
			<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
		</span>
	</el-dialog>

</template>
<script>
import request from '@/utils/request'
import {getDictionaryDataSelector}from '@/api/systemData/dictionary'
import {previewDataInterface}from '@/api/systemData/dataInterface'
export default {
    data() {
      return {
        visible: false,
        isDetail: false,
        dataForm: {
					min:undefined,
					max:undefined,
					commission:undefined,
					description:undefined,

        },
        rules: {
						min:[
						{
							required:true,
							message:'请输入最小月份',
							trigger:'blur'
						},
						],
						max:[
						{
							required:true,
							message:'请输入最大月份',
							trigger:'blur'
						},
						],
						commission:[
						{
							required:true,
							message:'请输入提成',
							trigger:'blur'
						},
						],

        },


      }
    },
    created() {

    },
    methods: {

           goBack() {
                    this.$emit('refresh')
                },
      init(id, isDetail) {

        this.dataForm.id = id || 0;
        this.visible = true;
        this.isDetail = isDetail || false;
        this.$nextTick(() => {
          this.$refs['elForm'].resetFields();
          if (this.dataForm.id) {
            request({
              url: '/api/Jiushi/Jsconfig/' + this.dataForm.id,
              method: 'get'
            }).then(res =>{
              this.dataForm = res.data;

            })
          }
        })
      },
      // 表单提交
      dataFormSubmit() {

        this.$refs['elForm'].validate((valid) => {
          if (valid) {
            if (!this.dataForm.id) {
              request({
                url: '/api/Jiushi/Jsconfig',
                method: 'post',
                data: this.dataForm,
              }).then((res) =>{
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () =>{
                    this.visible = false;
                    this.$emit('refresh', true);
                  }
                })
              })
            } else {
              request({
                url: '/api/Jiushi/Jsconfig/' + this.dataForm.id,
                method: 'PUT',
                data: this.dataForm
              }).then((res) =>{
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () =>{
                    this.visible = false;
                    this.$emit('refresh', true);
                  }
                })
              })
            }
          }
        })
      },

    }
  }
  </script>